<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
require_once(dirname(__FILE__) . "/../../dbcom/RagionCom.php");
require_once(dirname(__FILE__) . "/../../dbcom/MachineCom.php");
require_once(dirname(__FILE__) . "/../../dbcom/UserCom.php");
require_once(dirname(__FILE__) . "/../../common/Common.php");

$ragioncom = new RagionCom();
$machinecom = new MachineCom();
$usercom = new UserCom();
$common = new Common();
//$communityarr = $ragioncom->getRagionByType(2);

$userid = $common->getLogin();
if (!isset($userid) || empty($userid)) {
    header('Location:./../login.php');
}

$user = $usercom->getUserById($userid);
if ($user['role'] != 0) {
    $mechine = $machinecom->getwMechine($user['community_id']);
} else {
    $mechine = $machinecom->getMechine();
}

$mymechine = array();
if (!empty($mechine)) {
    foreach ($mechine as $k => $v) {
        $mymechine[$k]['id'] = $v['id'];
        $mymechine[$k]['des'] = $v['des'];
        $community = $ragioncom->getRagionById($v['community_id']);
        $mymechine[$k]['community'] = $community['name'];
    }
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
        <style type="text/css">
            body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
        </style>
        <link href="../public/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
        <link href="../public/css/font-awesome.css?v=4.4.0" rel="stylesheet">
        <link href="../public/css/animate.css" rel="stylesheet">
        <link href="../public/css/style.css?v=4.1.0" rel="stylesheet">
        <script src="../public/js/jquery.min.js?v=2.1.4"></script>
        <script src="../public/js/bootstrap.min.js?v=3.3.6"></script>
        <script src="../public/js/plugins/layer/layer.min.js"></script>
        <title>新增爬楼机</title>
    </head>
    <body>
        <div class="wrapper wrapper-content animated fadeInUp">
            <div class="row">
                <div class="col-sm-12">

                    <div class="ibox">
                        <div class="ibox-title">
                            <h5>服务管理</h5>
                            <div class="ibox-tools">
                                <a id="addnew" data-toggle="modal" data-target="#myModal1" class="btn btn-primary btn-xs">新增</a>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <div class="row m-b-sm m-t-sm">
                                <div class="col-md-1">

                                </div>
                                <div class="col-md-11">
                                    <div class="input-group">

                                    </div>
                                </div>
                            </div>

                            <div class="project-list">

                                <div class="project-list">
                                    <div class="table-responsive">
                                        <table class="table table-striped">
                                            <thead>
                                                <tr>
                                                    <td class="project-title">
                                                        <span>备注</span>
                                                    </td>
                                                    <td class="project-people">
                                                        <span>社区</span>
                                                    </td>
                                                    <td class="project-actions">
                                                        <span>操作</span>
                                                    </td>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                foreach ($mymechine as $v) {
                                                    ?>
                                                    <tr id="list<?= $v['id'] ?>" data-id="<?= $v['id'] ?>">
                                                        <td class="project-title">
                                                            <span><?= $v['des'] ?></span>
                                                        </td>
                                                        <td class="project-people">
                                                            <span><?= $v['community'] ?></span>
                                                        </td>
                                                        <td class="project-actions">
                                                            <a data-id="<?= $v['id'] ?>" class="btn btn-white btn-sm btn-det"><i class="fa fa-folder"></i> 删除 </a>
                                                        </td>
                                                    </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                        <div class="box" id="box"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
<script type="text/javascript">
    $(".btn-det").click(function () {
        var serviceid = $(this).data("id");
        var datastr = "cont=2&mechineid=" + serviceid;
        $.ajax({
            url: "/../../controller/mechine.php",
            type: "POST",
            data: datastr,
            success: function (e) {
                //console.log(e);
                var result = eval("(" + e + ")");
                if (result.code == 0) {
                    layer.msg('删除成功', {
                        time: 2000, //20s后自动关闭
                        btn: ['OK']
                    });
                    $("#list" + result.data).css("display", "none");
                } else {
                    layer.msg('删除失败请刷新重试', {
                        time: 2000, //20s后自动关闭
                        btn: ['OK']
                    });
                    return;
                }
                return;
            }
        });
    });
</script>